/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package l1j.server.server.npc.action;

import org.w3c.dom.Element;

import l1j.server.server.model.L1Object;
import l1j.server.server.model.Instance.L1NpcInstance;
import l1j.server.server.model.Instance.L1PcInstance;

public abstract class L1NpcAction {
	private String _name;
	private int _npcId = 0;

	public L1NpcAction(Element element) {
		_name = element.getAttribute("Name");
		_name = _name.equals("") ? null : _name;
		_npcId = L1NpcXmlParser.getIntAttribute(element, "NpcId", 0);
	}

	public boolean acceptsRequest(String actionName, L1PcInstance pc,
			L1Object obj) {
		if (_npcId != 0) {
			if (!(obj instanceof L1NpcInstance)) {
				return false;
			}
			if (_npcId != ((L1NpcInstance) obj).getNpcTemplate().get_npcId()) {
				return false;
			}
		}
		if (_name == null) {
			return true;
		}
		return actionName.equals(_name);
	}

	public abstract String execute(String actionName, L1PcInstance pc,
			L1Object obj, byte args[]);
}
